using NUnit.Framework;

// ReSharper disable InconsistentNaming
namespace NFreeMarker.Tests.Template
{
    public class TemplateTests_ProcessLogicalOperations
    {
        [TestFixture]
        public class When_processing_an_add_expression : TemplateTestsBase
        {
            [Test]
            public void Assure_true_is_returned_when_both_left_and_right_side_is_true()
            {
                SetTemplateContent("${(true && true)?string}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("true"));
            }
 
            [Test]
            public void Assure_false_is_returned_when_left_side_is_true_and_right_side_is_false()
            {
                SetTemplateContent("${(true && false)?string}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("false"));
            }

            [Test]
            public void Assure_false_is_returned_when_left_side_is_false_and_right_side_is_true()
            {
                SetTemplateContent("${(false && true)?string}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("false"));
            }
            [Test]
            public void Assure_false_is_returned_when_both_left_and_right_side_is_false()
            {
                SetTemplateContent("${(false && false)?string}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("false"));
            }
        }

        [TestFixture]
        public class When_processing_an_or_expression : TemplateTestsBase
        {
            [Test]
            public void Assure_true_is_returned_when_both_left_and_right_side_is_true()
            {
                SetTemplateContent("${(true || true)?string}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("true"));
            }
 
            [Test]
            public void Assure_true_is_returned_when_left_side_is_true_and_right_side_is_false()
            {
                SetTemplateContent("${(true || false)?string}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("true"));
            }

            [Test]
            public void Assure_true_is_returned_when_left_side_is_false_and_right_side_is_true()
            {
                SetTemplateContent("${(false || true)?string}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("true"));
            }
            [Test]
            public void Assure_false_is_returned_when_both_left_and_right_side_is_false()
            {
                SetTemplateContent("${(false || false)?string}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("false"));
            }
        }

        [TestFixture]
        public class When_processing_a_not_expression : TemplateTestsBase
        {
            [Test]
            public void Assure_false_is_returned_when_the_value_is_true()
            {
                SetTemplateContent("${(!true)?string}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("false"));
            }
 
            [Test]
            public void Assure_true_is_returned_when_the_value_is_false()
            {
                SetTemplateContent("${(!false)?string}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("true"));
            }
        }
    }
}
// ReSharper enable InconsistentNaming
